home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Apple II Magazines (PO)
/
Nibble Volume 11, No. 01 (1990-01)(MindCraft Publishing)(Side A)[a].zip
/
Nibble Volume 11, No. 01 (1990-01)(MindCraft Publishing)(Side A)[a].po
/
FR.OPTIONS.ASM.txt
< prev
next >
Wrap
Text File
|
1996-12-24
|
32KB
|
818 lines
****************************************
* *
* FR.OPTIONS.ASM Source Code *
* by Sandy Mossberg *
* *
* APW Assembler *
* *
* Copyright (C) 1989 *
* by MindCraft Publ. Corp. *
* Concord, MA 01742 *
* *
****************************************
*****************************************************************
*
DoOpen start
*
* Open window containing file contents:
*
*****************************************************************
using GlobalData
PushWord #120 ;X coord of upper left corner
PushWord #40 ;Y coord of upper left corner
PushLong #SFPrompt ;ptr to prompt string
PushLong #0 ;ptr to filter (none)
PushLong #SFTypeList ;ptr to file type list
PushLong #SFReplyRec ;ptr to reply record
_SFGetFile
lda SFGood ;which button closed box?
beq Done ;Cancel button hit
PushWord #257 ;Okay button hit
_DisableMItem ;dim Open File item
jsr GetFile ;read selected file into memory
jsr ShowWindow ;display window
Done rts
;................................................................
;
GetFile anop
;
; Read selected Ascii file into memory:
;
; Convert file name P-string in standard files reply record to
; class 1 GS/OS input str at MyFile (i.e. change leading length
; byte to leading length word). Also convert same P-string
; to title of text window (i.e. flank file name with spaces
; because window will contain racing stripes in title bar):
short
lda SFFilename ;get length byte of P-string
sta MyFile ;put leading length word
stz MyFile+1 ; in input string
clc ;bump length byte by 2 in wind
adc #2 ; title string to accommodate
sta TextWindStr ; leading and trailing spaces
lda #$20 ;put leading space
sta TextWindStr+1 ; in window title
ldy #0 ;copy file name to
GF01 lda SFFilename+1,y ; both locations
cmp #$60
bcc GF02
and #$DF ;ensure upper case
GF02 sta MyFile+2,y
sta TextWindStr+2,y
iny
cpy SFFilename
bcc GF01
lda #$20 ;put trailing space
sta TextWindStr+2,y ; in window title
long ;set 16-bit regs
; Read file into memory:
_OpenGS OpenParm ;open selected file
jsr HandlErr
lda OpenRefNum ;stuff reference number
sta EOFRefNum ; into other parmlists
sta ReadRefNum
sta CloseRefNum
_GetEOFGS EOFParm ;get size of file in bytes
jsr HandlErr
lda EOF ;stuff file size into
sta RequestCnt ; Read parmlist
lda EOF+2
sta RequestCnt+2
anop ;reserve memory for data buffer
PushLong #0 ;space for result
PushLong EOF ;size of space
PushWord MasterID ;master ID
PushWord #$C010 ;locked, fixed, one bank
PushLong #0 ;not used
_NewHandle ;allocate space
jsr HandlErr
PullLong DataBufHndl ;save handle to data buffer
lda [DataBufHndl] ;dereference handle and
sta DataBufPtr ; store ptr to data buffer
sta DataBuf ; in Read parmlist
ldy #2
lda [DataBufHndl],y
sta DataBufPtr+2
sta DataBuf+2
_ReadGS ReadParm ;read file into data buffer
jsr HandlErr
_CloseGS CloseParm ;close file
jmp HandlErr
;................................................................
;
ShowWindow anop
;
; Display window on SHR screen:
;
; Calculate data height of file in pixels,
; and ensure positive Ascii file bytes:
lda #9*2 ;allow top and bottom margins
sta DataSize ; (row = 9 pixels)
ldy #0 ;zero char index
SW01 lda [DataBufPtr],y ;get 2 bytes from file buffer
and #$FF7F ;ensure pos Ascii lo byte
sta [DataBufPtr],y ;write char back to file buffer
and #$FF ;ignore hi byte
cmp #$0D
bne SW02 ;CR not found
clc
lda DataSize ;CR found so add 9 pixels
adc #9 ; for another line
sta DataSize
SW02 iny ;bump char index
cpy EOF
bcc SW01 ;not yet at end of file
cmp #$3FFF ;max window height = 16383
bcc SW03 ;max height not exceeded
; Entire file cannot be displayed because of QuickDraw II limits,
; so check whether user wishes to display partial file:
pha ;space for result
PushWord #0 ;C-string
PushLong #0 ;no substitution array
PushLong #AlertStr ;ptr to alert string
_AlertWindow ;display alert window
pla ;get button ID
dec a
beq SW04 ;Cancel button hit
lda #$3FFF ;user wants partial file shown;
sta DataSize ; clip window to max height
; Display window:
SW03 PushLong #0 ;space for result
PushLong #TextWind ;ptr to window parmlist
_NewWindow ;display window
jsr HandlErr
PullLong TextWindPtr ;save ptr to window's GrafPort
rts
; Cancel window:
SW04 PushLong DataBufHndl ;handle to file data buffer
_DisposeHandle ;release handle and free memory
rts
;................................................................
;
; DoOpen data:
;
SFReplyRec anop ;standard files reply record
SFGood ds 2 ;true = open, false = cancel
SFFileType ds 2 ;file type code
SFAuxtype ds 2 ;auxiliary type code
SFFilename ds 16 ;file name string (prefix 0)
SFPathname ds 129 ;full path string (prefix 0)
SFPrompt anop ;standard files prompt string
str 'Select an Ascii file to read:'
SFTypeList anop ;list of file types to display
dc i1'SFTypeCnt' ;number of file types
dc i1'$04' ;TXT
dc i1'$B0' ;SRC
SFTypeCnt equ *-SFTypeList-1 ;calculate number of file types
TextWindPtr ds 4 ;ptr to text window
TextWindStr ds 18 ;name string for text window
TextWind anop ;window parmlist
dc i2'TWEnd-TextWind' ;size of table in bytes
dc i2'%1101110110100101' ;description of frame
dc i4'TextWindStr' ;ptr to title string
dc i4'0' ;refcon
dc i2'0,0,0,0' ;zoom size (full screen)
dc i4'ColorTable' ;ptr to color table
dc i2'0,0' ;content/data offset
DataSize dc i2'0,1020' ;data area height/width
dc i2'0,0' ;grow height/width
dc i2'9,12' ;arrow scroll vert/horiz
dc i2'144,592' ;page scroll vert/horiz
dc i4'0' ;info bar refcon
dc i2'0' ;info bar height
dc i4'0' ;ptr to frame defproc
dc i4'0' ;ptr to info bar defproc
dc i4'WindUpdate' ;ptr to update defproc
dc i2'30,90,180,420' ;coords of content region
dc i4'-1' ;plane (front)
dc i4'0' ;ptr to memory
TWEnd anop
ColorTable anop ;color table for text window
dc i2'$0000' ;frame
dc i2'$0F00' ;title string and inactive title bar
dc i2'$020F' ;active title bar (racing stripes)
dc i2'$00F0' ;grow box and alert's middle outline
dc i2'$00F0' ;info bar and alert's inside outline
AlertStr anop ;alert string
dc c'0',i'60,160,115,480' ;coordinates
dc c'4/' ;caution icon, separator
dc h'01',c'J',i'1' ;center text
dc h'0D',c'Entire file cannot' ;message text
dc c' be displayed.',h'0D'
dc c'/^#6' ;separator, Continue default
dc c'/#1' ;separator, Cancel
dc h'00' ;zero terminator
MyFile ds 17 ;input filename (GS/OS class 1)
OpenParm anop ;Open parmlist (GS/OS class 1)
dc i2'2' ;pCount = 2 (input)
OpenRefNum ds 2 ;reference number (result)
dc i4'MyFile' ;ptr to filename (input)
ReadParm anop ;Read parmlist (GS/OS class 1)
dc i2'4' ;pCount = 4 (input)
ReadRefNum ds 2 ;reference number (input)
DataBuf ds 4 ;ptr to data buffer (input)
RequestCnt ds 4 ;bytes requested (input)
TransCnt ds 4 ;bytes transferred (result)
CloseParm anop ;Close parmlist (GS/OS class 1)
dc i2'1' ;pCount = 1 (input)
CloseRefNum ds 2 ;reference number (input)
end
*****************************************************************
*
WindUpdate start
*
* TaskMaster uses this code to update contents of window:
*
*****************************************************************
using GlobalData
; Since TaskMaster calls this subroutine, switch
; to application's data bank and direct page:
phb ;save entry data bank
phd ;save entry direct page
phk ;equate program bank
plb ; with data bank
lda MyDP ;use application's
tcd ; direct page
; Locate first visible line line in file:
PushLong #WindPort ;ptr to port rectangle's coords
_GetPortRect ;get window's port rectangle
lda #9 ;row zero begins 9 pixels down
sta RowLoc
ldy #-1 ;prepare to zero file char indx
CheckTop lda RowLoc ;compare row position with
cmp WindPort+top ; top of port rectangle
bcs DrawWind ;first visible line located
CheckEOF iny ;compare file char index with
cpy EOF ; end-of-file position
bcs Done ;end of file found
lda [DataBufPtr],y ;get file char
and #$FF ;isolate lo byte
cmp #$0D
bne CheckEOF ;CR not found
clc
lda RowLoc ;add 9 pixels for next row
adc #9
sta RowLoc
bra CheckTop
; Draw contents of window:
DrawWind iny ;goto start of 1st visible line
phy ;protect file char index
lda #4 ;set left margin for
sta LeftEdge ; drawing in window
pha ;horizontal coord (L edge)
PushWord RowLoc ;vertical coord (row position)
_MoveTo ;put pen at specified point
ply ;restore file char index
NextLine jsr DrawLine ;draw line in window
phy ;protect file char index
PushLong #PenLoc ;ptr to pen coordinates
_GetPen ;get pen position
ply ;restore file char index
iny ;compare file char index with
cpy EOF ; end-of-file position
bcs Done ;end of file found
lda WindPort+bottom ;compare bottom of port
clc ; rectangle with current
adc #9 ; vertical pen position
cmp PenLoc+v
bcs NextLine ;not yet at bottom of window
Done pld ;restore entry direct page
plb ;restore entry data bank
rtl ;RTL required by TaskMaster
;................................................................
;
; WindUpdate data:
;
WindPort ds 8 ;coords of port rectangle
RowLoc ds 2 ;row position in file
end
*****************************************************************
*
DrawLine start
*
* Draw one line to window or printer:
*
*****************************************************************
using GlobalData
stz CharCnt ;zero char count
sty RowStart ;save starting position
GetLine lda [DataBufPtr],y ;get char
and #$FF ;isolate low byte
cmp #$0D
beq ShowLine ;CR indicates end of line
inc CharCnt ;bump char count
iny ; and char index
cpy EOF
bne GetLine ;end of file not found
dey ;end of file found
ShowLine phy ;protect file char index
lda CharCnt ;if char count is zero
beq MoveDown ; then bare CR found
clc ;calc ptr to start of line
lda DataBufPtr
adc RowStart
tax
lda DataBufPtr+2
adc #0
pha ;hi byte of ptr to line
phx ;lo byte of ptr to line
PushWord CharCnt ;number of bytes to draw
_DrawText ;draw entire line
MoveDown PushLong #PenLoc ;get current pen location
_GetPen ; (at end of line)
PushWord LeftEdge ;horiz coord (left edge)
clc ;calculate vertical position
lda PenLoc+v ; by adding 9 to current
adc #9 ; pen location
pha ;vert coord (line position)
_MoveTo ;put pen at specified location
ply ;restore file char index
rts
;................................................................
;
; DrawLine data:
;
CharCnt ds 2 ;number of chars in row
RowStart ds 2 ;starting position of row
end
*****************************************************************
*
DoChooser start
*
* Select printer and port driver via chooser dialog:
*
*****************************************************************
pha ;space for result
_PrChoosePrinter ;conduct chooser dialog
pla ;trash Boolean: true = new
rts ; driver, false = same driver
end
*****************************************************************
*
DoSetup start
*
* Select page setup via style dialog:
*
*****************************************************************
jsr SetPrintRec ;set print record
pha ;space for result
PushLong PrtRecHndl ;handle to print record
_PrStlDialog ;conduct setup dialog
pla ;trash Boolean: true = Okay
rts ; hit, false = Cancel hit
end
*****************************************************************
*
SetPrintRec start
*
* Establish default print record:
*
*****************************************************************
using GlobalData
lda PrtRecHndl
ora PrtRecHndl+2
beq SPR01 ;print record not allocated
anop ;validate current print record
pha ;space for result
PushLong PrtRecHndl ;handle to print record
_PrValidate
jsr HandlErr
pla ;trash Boolean: true = change,
rts ; false = no change
SPR01 anop ;allocate mem for print record
PushLong #0 ;space for result
PushLong #140 ;size of print record
PushWord MasterID ;master ID
PushWord #$C010 ;locked, fixed, one bank
PushLong #0 ;not used
_NewHandle ;allocate space
jsr HandlErr
PullLong PrtRecHndl ;save handle to data buffer
lda [PrtRecHndl] ;dereference handle
sta PrtRecPtr ; to print record
ldy #2
lda [PrtRecHndl],y
sta PrtRecPtr+2
anop ;set default print record
PushLong PrtRecHndl ;handle to print record
_PrDefault
jsr HandlErr
rts
end
*****************************************************************
*
DoPrint start
*
* Print contents of window:
*
*****************************************************************
using GlobalData
; Set default print record or validate current print record:
jsr SetPrintRec
; Conduct job dialog:
pha ;space for result
PushLong PrtRecHndl ;handle to print record
_PrJobDialog
pla ;get Boolean
bne Printit ;true = Okay hit so continue
rts ;false = Cancel hit so exit
Printit _WaitCursor ;display clock cursor
ldy #$50+6 ;get printing method byte
lda [PrtRecPtr],y ; in job subrecord of
and #$FF ; print record
sta PrtMethod
bne DocStart ;spooling; don't reset copies
ldy #$50+4 ;draft printing; get number
lda [PrtRecPtr],y ; of copies in job subrecord
sta NumCopies ; of print record
lda #1 ;ensure one copy in job sub-
sta [PrtRecPtr],y ; record of print record
; Initialize document GrafPort and make it current:
DocStart PushLong #0 ;space for result
PushLong PrtRecHndl ;handle to print record
PushLong #0 ;allocate new GrafPort
_PrOpenDoc
PullLong PrtDocPtr ;get ptr to doc's GrafPort
jsr CheckPrtErr ;check error
bcc PrintLoop ;no error
brl DocDone ;error, so abort printing
; Execute printing loop:
PrintLoop ldy #0
PageStart sty YSave ;protect file char index
PushLong PrtDocPtr ;ptr to document's GrafPort
PushLong #0 ;no scaling
_PrOpenPage ;begin new page
jsr CheckPrtErr ;check error
bcs PageDone ;error, so abort printing
PrintPage ldy #$02+6+bottom ;get bottom of page in info
lda [PrtRecPtr],y ; subrecord of print record
sta PageEnd
lda #0 ;set left margin for printing
sta LeftEdge
pha ;horizontal coordinate (L edge)
PushWord #9 ;vertical coordinate (1st row)
_MoveTo ;move pen to specified point
ldy YSave ;restore file char index
PrintLine jsr DrawLine ;draw line to window or printer
sty YSave ;protect file char index
PushLong #PenLoc ;ptr to pen coordinates
_GetPen ;get pen position
ldy YSave ;restore file char index
iny ;compare file char index with
cpy EOF ; end-of-file position
bcs PageDone ;end of file found
lda PenLoc+v
cmp PageEnd
bcc PrintLine ;not at end of page
sty YSave ;protect file char index
PushLong PrtDocPtr ;ptr to document's GrafPort
_PrClosePage ;end printing of page
jsr CheckPrtErr ;check error
bcs DocDone ;error, so abort printing
ldy YSave ;restore file char index
bra PageStart ;loop back for another page
; Terminate printing loop:
PageDone PushLong PrtDocPtr ;ptr to document's GrafPort
_PrClosePage ;end printing of page
DocDone PushLong PrtDocPtr ;ptr to document's GrafPort
_PrCloseDoc ;close document's GrafPort
pha ;space for result
_PrError
pla ;get last printer error code
bne Done ;error found; skip spooling
lda PrtMethod
beq Spoolit ;draft printing; skip mem check
_CompactMem ;compact memory
PushLong #0 ;space for result
_MaxBlock
PullLong MaxBlkSize ;size of largest free mem block
lda MaxBlkSize
cmp #$2800
lda MaxBlkSize+2
sbc #0
bcc Done ;mem block < 10K; skip spooling
Spoolit PushLong PrtRecHndl ;handle to print record
PushLong #0 ;allocate new GrafPort
PushLong #0 ;allocate printer status record
_PrPicFile ;print spooled document
lda PrtMethod
bne Done ;spool printing; don't recycle
dec NumCopies ;draft printing, check copies
beq Done ;done
jsr CheckPMBuf ;ensure empty print buffer
bcs Done ;extended interface call error
brl DocStart ;draft-print another copy
Done _InitCursor ;show arrow cursor
rts
;................................................................
;
; Check for Print Manager error:
;
CheckPrtErr bcc CPE1 ;also check error location
rts
CPE1 pha ;space for result
_PrError ;check last error
pla ;get last PM error code
sec ;assume error
bne CPE2 ;error code found
clc ;signal no error
CPE2 rts
;................................................................
;
; DoPrint data:
;
YSave ds 2 ;contents of Y-reg
NumCopies ds 2 ;number of copies to be printed
PrtMethod ds 2 ;printing method (0=draft, non0=spool)
PrtDocPtr ds 4 ;ptr to document's GrafPort
PageEnd ds 2 ;bottom of page rectangle
MaxBlkSize ds 4 ;size of largest free memory block
end
*****************************************************************
*
CheckPMBuf start
*
* Ensure empty buffer using extended serial port firmware calls:
*
*****************************************************************
using GlobalData
PortNamePtr gequ $18 ;ptr to name of active device
EIHndl gequ $1C ;handle to bank zero space
EIPtr gequ $20 ;ptr to bank zero space
Emulstack gequ $010100 ;emulation mode stack ptr
; Find slot number of printer:
CheckPMBuf anop
PushLong #0 ;space for result
ldx #$2913 ;PrGetPortDvrName
jsl $E10000
PullLong PortNamePtr ;ptr to name of driver
short ;set 8-bit regs
ldy #2
lda [PortNamePtr],y ;get 1st char in device name
and #$DF ;ensure upper case
cmp #'A'
bne GetSlot ;parallel card not found
sec ;parallel card found so abort
rts
GetSlot ldx #1
txy
lda [PortNamePtr],y ;get 1st char in device name
and #$DF ;ensure upper case
cmp #'M'
bne GotSlot ;starts with "P" = printer
inx ;starts with "M" = modem
GotSlot txa ;A-reg holds printer's slot
; Modify code to reflect printer's slot ROM:
ora #$C0 ;get printer's slot ROM address
sta GetOffset+2 ;modify calls
sta DoOutBuf+2
sta DoQStat+2
; Modify code to reflect extended interface dispatch address:
GetOffset lda >$C012 ;get offset to dispatch address
sta DoOutBuf+1 ;modify calls
sta DoQStat+1
; Allocate bank zero space for extended interface command calls:
long ;set 16-bit regs
PushLong #0 ;space for result
PushLong #BZEnd-BZStart ;size of direct page space
PushWord MasterID ;master ID
PushWord #$C005 ;lock, fix, align, fixed bank
PushLong #0 ;bank zero is the fixed bank
_NewHandle ;allocate space
jsr HandlErr
PullLong EIHndl ;save handle to bank zero space
lda [EIHndl] ;dereference handle to get
sta EIPtr ; ptr to bank zero space
sta GoBZ+1 ;modify bank zero call addr
ldy #2
lda [EIHndl],y
sta EIPtr+2
; Copy image of bank zero code to bank zero:
shortm ;set 8-bit A and memory
ldy #BZEnd-BZStart-1
CopyLoop lda BZStart,y
sta [EIPtr],y
dey
bpl CopyLoop
longm ;set 16-bit A and memory
; Invoke extended interface calls which now reside in bank zero:
GoBZ jsl $001000 ;modified above
; Dispose of handle to bank zero:
PushLong EIHndl
_DisposeHandle
; Check for extended interface call error and return to caller:
lda GOBReturn
bne ExtCmdErr ;call error
lda OQSReturn
beq CPMBRTS ;no call error
ExtCmdErr sec ;flag error
CPMBRTS rts
;................................................................
;
; IMAGE OF BANK ZERO CODE (this code copied to bank zero):
;
; Save entry environment:
BZStart phd ;save entry direct page
phb ;save entry data bank
tsc ;get stack ptr into
tax ; A and X regs
shortm ;set 8-bit A and memory
xba
dec a
beq SaveSP ;stack ptr already in page 1
lda #1 ;set stack to page one
xba
lda Emulstack ;set emulation mode stack ptr
tcs ; (don't worry about hi byte)
SaveSP phx ;save entry stack ptr
; Enter emulation mode and set new environment:
emulation ;enter emulation mode
pea 0 ;put direct page into page zero
pld
lda #0 ;zero program bank
pha
plb
; Ensure empty printer buffer via extended interface calls:
TestBuf emulation ;enter emulation mode
lda #GOBCmdList ;point to command list
ldx #>GOBCmdList
ldy #^GOBCmdList
DoOutBuf jsr $C000 ;modified to call GetOutBuffer
lda >GOBReturn
bne RestEnviron
lda #OQSCmdList ;point to command list
ldx #>OQSCmdList
ldy #^OQSCmdList
DoQStat jsr $C000 ;modified to call OutQStatus
lda >OQSReturn
bne RestEnviron
native long ;set native mode, 16-bit regs
lda >GOBBufLen ;ensure empty print buffer
dec a
cmp >OQSBufLen
bne TestBuf
; Reenter native mode and restore environment:
RestEnviron native long ;set native mode, 16-bit regs
plx ;restore entry stack ptr
txs
plb ;restore entry data bank
pld ;restore entry direct page
rtl
BZEnd anop
;................................................................
;
; CheckPMBuf data (this code not copied to bank zero):
;
GOBCmdList anop ;GetOutBuffer command list
dc h'04' ;pCount = 4
dc h'11' ;command code
GOBReturn ds 2 ;return code (output)
ds 4 ;buffer address (output)
GOBBufLen ds 2 ;buffer length (output)
OQSCmdList anop ;OutQStatus
dc h'04' ;pCount = 4
dc h'17' ;command code
OQSReturn ds 2 ;return code (output)
OQSBufLen ds 2 ;space remaining in buffer (output)
ds 2 ;reserved (output)
end